<template>
    <!-- AI工具集 -->
    <div class=" margin_top">
        <headers :pageindex="4"></headers>
        <div class="aibox" v-if="ismobile">
            <div class="toolimg">AI工具箱</div>
            <div class="bigli">
                <div class="li " v-for="(item, index) in navlist" @click="clicknav(index)"
                    :class="index === active1 ? 'active' : ''">{{ item.value }}
                </div>
            </div>
            <titleline :miantitle="'TEXT LANGUAGE'" :explaintitle="'文本语言'"></titleline>
            <div v-if="navlist[active1].children" class="nav2 shouzhi"
                :style="'width:' + navlist[active1].children.length * 6 + 'rem'">
                <div v-for="(item, index) in navlist[active1].children" @click="clicknav2(index)"
                    :class="index === active2 ? 'active' : ''">{{
                        item.value }}
                </div>
            </div>
            <ul>
                <li v-for="(item, index) in toolist" @click="goai(item)">
                    <div class="top">
                        <img :src="item.logo" alt="">
                        <div>
                            <div>{{ item.name }}</div>
                            <div>{{ item.summary }}</div>
                        </div>
                    </div>
                    <div class="bottom">
                        <div class="btn">文本语言</div>
                        <div class="btn">聊天机器</div>
                    </div>
                </li>
            </ul>
            <div class="fenye2" v-if="page.TotalCount > page.size">
                <div>
                    <el-pagination background @current-change="handleCurrentChange" :page-size="page.size"
                        :current-page="page.current" layout="prev, pager, next" :total="page.TotalCount">
                    </el-pagination>
                </div>
            </div>
        </div>
        <div class="aiboxpc " v-if="!ismobile">
            <div class="box">
                <div class="navleft">
                    <div class="navli shouzhi" v-for="(item, index) in navlist" @click="clicknav(index)"
                        :class="index === active1 ? 'activebgs' : ''">
                        <span class="iconfont" :class="item.icon"></span>
                        {{ item.value }}
                        <!-- <span class="iconfont icon-qitagongju-xiangyou xiangyou"></span> -->
                    </div>
                </div>
                <div class="content" v-if="navlist[active1].children">
                    <div class="nav2 shouzhi" :style="'width:' + navlist[active1].children.length * 6 + 'rem'">
                        <div class="shouzhi" v-for="(item, index) in navlist[active1].children" @click="clicknav2(index)"
                            :class="index === active2 ? 'active' : ''">{{
                                item.value }}
                        </div>
                    </div>
                    <ul class="pcul shouzhi">
                        <li v-for="(item, index) in toolist" @click.stop="goai(item)">
                            <div class="top">
                                <img :src="item.logo" alt="">
                                <div>
                                    <div>{{ item.name }}</div>
                                    <div>{{ item.summary }}</div>
                                </div>
                            </div>
                            <div class="bottom">
                                <div class="btn">{{ navlist[active1].value }}</div>
                                <div class="btn">{{ navlist[active1].children[active2].value }}</div>
                                <span class="icon iconfont icon-youjiantou_huaban shouzhi" @click.stop="goweb(item)"></span>
                            </div>
                        </li>
                    </ul>
                    <div class="fenye" v-if="page.TotalCount > page.size">
                        <div>
                            <el-pagination background @current-change="handleCurrentChange" :page-size="page.size"
                                :current-page="page.current" layout="prev, pager, next" :total="page.TotalCount">
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <bottoms></bottoms>
    </div>
</template>

<script>


import Swiper from 'swiper'
import 'swiper/css/swiper.min.css'
import { WOW } from "wowjs";
import bottoms from "./modle/bottoms.vue"
import headers from "./modle/headers.vue"
import titleline from "./modle/titleline.vue"

export default {
    name: 'HelloWorld',
    components: {
        headers,
        bottoms,
        titleline
    },
    data() {
        return {
            toolist: [],
            active2: 0,
            nav2: [{
                id: "", name: "聊天机器"
            }, {
                id: "", name: "文案写作"
            }, {
                id: "", name: "文档工具"
            }],
            navlist: [{
                id: "", name: "文本语言", class: "icon-wode_yuyan_icon"
            }, {
                id: "", name: "图像绘画", class: "icon-noun_pencilcup_"
            }, {
                id: "", name: "音频处理", class: "icon-yinpinchuliqi"
            }, {
                id: "", name: "视频处理", class: "icon-shipinchuli"
            }, {
                id: "", name: "代码编程", class: "icon-yilian-kaifagongju"
            }, {
                id: "", name: "其他工具", class: "icon-a-1_qitagongju"
            }],
            active1: 0,
            ismobile: false,
            page: {
                current: 1,
                size: 12,
                TotalCount: 0
            }
        }
    },
    created() {
        this.gettype()
    },
    methods: {
        handleCurrentChange(val) {
            this.page.current = val
            this.get_tool()
        },
        goweb(item) {
            window.open(item.link)
        },
        get_tool() {
            this.$api.get(
                "/api/PortalHome/get_tool",
                {
                    categories_id: this.navlist[this.active1].children[this.active2].key,
                    page_index: this.page.current,
                    page_size: this.page.size
                },
                (r) => {
                    this.toolist = r.DATA
                    this.page.TotalCount = r.TotalCount
                },
                (f) => { }
            );
        },
        gettype() {
            this.$api.get(
                "/api/PortalHome/get_tool_categories",
                { category_type: 1 },
                (r) => {
                    this.isfirst = true
                    this.navlist = r.DATA
                    this.get_tool()
                },
                (f) => { }
            );
        },

        goai(item) {
            console.log(item)
            this.$router.push({
                path: '/ai_explain', query: {
                    id: item.id, word1: this.navlist[this.active1].value,
                    word2: this.navlist[this.active1].children[this.active2].value
                }
            })
        },
        clicknav2(index) {
            this.page.current = 1
            this.active2 = index
            this.get_tool()
        },
        clicknav(index) {
            this.page.current = 1
            this.active1 = index
            this.active2 = 0
            this.get_tool()
        },
        apply() {
            this.$router.push({ path: '/experience' })
        }
    },
    mounted() {
        this.ismobile = this.isMobile()
        let that = this;
        window.addEventListener('resize', function () {
            that.ismobile = that.isMobile()
        });
    }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.fenye2 {
    margin: 20px 0;
}

.fenye {
    margin-top: 20px;
    overflow: hidden;
    padding-right: 90px;

    >div {
        float: right;
    }

}

.xiangyou {
    float: right;
}

.navli {
    line-height: 3rem;
    text-align: center;
}

.box {
    display: flex;
    width: 1200px;
    margin: 0 auto;

    .navleft {
        flex: 1;

        .navli {}
    }

    .content {
        flex: 5;
        padding-left: 1rem;
        box-sizing: border-box;

        .nav2 {
            background: rgb(224, 224, 224);
            margin-top: 1rem;
            margin-left: 3rem;
            display: linear-block;
        }

        .nav2 div:hover {
            background: rgb(243, 162, 161);
            color: white;
        }
    }
}

.aiboxpc {
    background: rgb(249, 249, 249);
    min-height: 80vh;
    padding-top: 7rem;
}

ul {
    margin: 0;
    padding: 0;
    width: 90%;
    margin: 0 auto;

    li {
        list-style: none;
        margin: 0;
        padding: 0;
        padding: 1rem 18px;
        border-radius: 0.6rem;
        margin-bottom: 0.6rem;
        box-shadow: 1px 2px 9px rgba(0, 0, 0, .11);

        .bottom {
            overflow: hidden;
            margin-top: 1rem;

            .btn {
                width: 6rem;
                text-align: center;
                font-size: 0.8rem;
                border-radius: 1.4rem;
                float: left;
                line-height: 2rem;
                margin-right: 0.5rem;

                background: #f8f5f5;
            }
        }

        .top {
            overflow: hidden;

            >img {
                width: 4rem;
                height: 4rem;
                border-radius: 0.8rem;
                float: left;

            }

            >div {
                float: left;
                font-size: 1rem;
                margin-left: 1.2rem;
                width: 60%;

                >div:nth-child(1) {
                    margin-top: 0.7rem;
                }

                >div:nth-child(2) {
                    font-size: 0.8rem;
                    margin-top: 0.3rem;
                    width: 100%;

                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    -o-text-overflow: ellipsis;

                }

            }

        }
    }
}

.pcul {
    overflow: hidden;

    li {
        width: 17rem;
        float: left;
        margin-right: 0.8rem;
        background: white;
    }

    .bottom {
        border-top: solid 1px #f1f3f4;
        padding-top: 0.5rem;

        .btn {
            width: 5rem;
            text-align: center;
            font-size: 0.7rem;
            border-radius: 1.4rem;
            float: left;
            line-height: 1.5rem;
            margin-right: 0.5rem;
            background: #f8f5f5;
        }

        .icon {
            float: right;
            margin-top: 0.6rem;
        }
    }
}

.nav2 {
    border-radius: 2rem;
    overflow: hidden;
    background: #f8f5f5;
    // width: 18rem;
    margin-left: 0.8rem;
    margin-bottom: 1rem;

    >div {
        line-height: 2.4rem;
        border-radius: 2rem;
        float: left;
        text-align: center;
        font-size: 0.9rem;
        width: 6rem;
    }
}

.bigli {
    width: 90%;
    background: #268bd2;
    overflow: hidden;
    margin: 1rem auto;
    margin-bottom: 0rem;

    .li {
        float: left;
        width: 33.33%;
        text-align: center;
        color: white;
        line-height: 2.5rem;
        transition: color 0.20s, border-color 0.20s, background-color 0.20s, background-image 0.20s;
        transition-timing-function: linear;
        border-left: solid 1px rgba(255, 255, 255, 0.3);
        border-bottom: solid 1px rgba(255, 255, 255, 0.3)
    }
}

.active {
    background-color: #dc322f;
    color: white;
}

.toolimg {
    background-image: linear-gradient(0deg, rgb(203, 75, 22) 0%, rgb(211, 54, 130) 100%);
    font-size: 4rem;
    text-align: center;
    color: white;
    font-weight: bold;
    line-height: 13rem;
}

.activebgs {
    background: #efefef;
}
</style>
